package org.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class Test {
    public static void main(String[] args)  throws Exception {

            Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root"
        );
        System.out.println("数据库连接成功");
        String sql="insert into llkp(username,password,nickname,age)" +
                "values(?,?,?,?)";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1,"刘大钊");
        ps.setString(2,"123456");
        ps.setString(3,"lkp");
        ps.setInt(4,18);
        int num = ps.executeUpdate();
        if(num>0)
            System.out.println("注册成功");
        else
            System.out.println("注册失败");

         System.out.println("键盘敲烂,薪资过万!");    

    }
}
